/*
 * Copyright 2022 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mx.ymate.security.base.model;

import net.ymate.platform.core.beans.annotation.PropertyState;
import net.ymate.platform.core.persistence.IShardingable;
import net.ymate.platform.core.persistence.annotation.*;
import net.ymate.platform.persistence.jdbc.IDatabase;
import net.ymate.platform.persistence.jdbc.IDatabaseConnectionHolder;
import net.ymate.platform.persistence.jdbc.query.AbstractFieldConditionBuilder;
import net.ymate.platform.persistence.jdbc.query.FieldCondition;
import net.ymate.platform.persistence.jdbc.query.Query;
import net.ymate.platform.persistence.jdbc.support.BaseEntity;

/**
 * SecurityRolePermission generated By EntityMojo on 2022/07/03 14:13:14
 *
 * @author YMP (https://www.ymate.net/)
 */
@Entity(SecurityRolePermission.TABLE_NAME)
@Comment("角色权限表")
public class SecurityRolePermission extends BaseEntity<SecurityRolePermission, String> {

    private static final long serialVersionUID = 1L;

    @Id
    @Property(name = FIELDS.ID, nullable = false, length = 32)
    @Comment("id")
    @PropertyState(propertyName = FIELDS.ID)
    private String id;

    
    @Property(name = FIELDS.CLIENT, nullable = false, length = 100)
    @Comment("客户端")
    @PropertyState(propertyName = FIELDS.CLIENT)
    private String client;

    
    @Property(name = FIELDS.ROLE_ID, nullable = false, length = 32)
    @Comment("角色id")
    @PropertyState(propertyName = FIELDS.ROLE_ID)
    private String roleId;

    
    @Property(name = FIELDS.PERMISSON_ID, nullable = false, length = 32)
    @Comment("权限id")
    @PropertyState(propertyName = FIELDS.PERMISSON_ID)
    private String permissonId;

    
    @Property(name = FIELDS.CREATE_TIME, nullable = false, length = 19)
    @Default("0")
    @Comment("创建时间")
    @PropertyState(propertyName = FIELDS.CREATE_TIME)
    private Long createTime;

    
    @Property(name = FIELDS.GROUP_NAME, nullable = false, length = 32)
    @Comment("权限组名称")
    @PropertyState(propertyName = FIELDS.GROUP_NAME)
    private String groupName;

    
    @Property(name = FIELDS.PERMISSION_NAME, nullable = false, length = 32)
    @Comment("权限名称")
    @PropertyState(propertyName = FIELDS.PERMISSION_NAME)
    private String permissionName;

    
    @Property(name = FIELDS.PERMISSION_CODE, nullable = false, length = 100)
    @Comment("权限码")
    @PropertyState(propertyName = FIELDS.PERMISSION_CODE)
    private String permissionCode;


    public SecurityRolePermission() {
    }

    public SecurityRolePermission(IDatabase dbOwner) {
        super(dbOwner);
    }


    public SecurityRolePermission(String id,String client, String roleId, String permissonId, Long createTime, String groupName, String permissionName, String permissionCode) {
        this.id = id;
        this.client = client;
        this.roleId = roleId;
        this.permissonId = permissonId;
        this.createTime = createTime;
        this.groupName = groupName;
        this.permissionName = permissionName;
        this.permissionCode = permissionCode;
    }

    public SecurityRolePermission(IDatabase dbOwner, String id, String client, String roleId, String permissonId, Long createTime, String groupName, String permissionName, String permissionCode) {
        super(dbOwner);
        this.id = id;
        this.client = client;
        this.roleId = roleId;
        this.permissonId = permissonId;
        this.createTime = createTime;
        this.groupName = groupName;
        this.permissionName = permissionName;
        this.permissionCode = permissionCode;
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public void setId(String id) {
        this.id = id;
    }

    public String getClient() {
        return client;
    }

    public void setClient(String client) {
        this.client = client;
    }

    public String getRoleId() {
        return roleId;
    }

    public void setRoleId(String roleId) {
        this.roleId = roleId;
    }

    public String getPermissonId() {
        return permissonId;
    }

    public void setPermissonId(String permissonId) {
        this.permissonId = permissonId;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public String getPermissionName() {
        return permissionName;
    }

    public void setPermissionName(String permissionName) {
        this.permissionName = permissionName;
    }

    public String getPermissionCode() {
        return permissionCode;
    }

    public void setPermissionCode(String permissionCode) {
        this.permissionCode = permissionCode;
    }


    public Builder bind() {
        return new Builder(this);
    }

    public static Builder builder() {
        return new Builder();
    }

        public static Builder builder(IDatabase dbOwner) {
            return new Builder(dbOwner);
        }

    public static class Builder {

        private final SecurityRolePermission targetEntity;

        public Builder() {
            targetEntity = new SecurityRolePermission();
        }

        public Builder(IDatabase dbOwner) {
            targetEntity = new SecurityRolePermission(dbOwner);
        }

        public Builder(SecurityRolePermission targetEntity) {
            this.targetEntity = targetEntity;
        }

        public SecurityRolePermission build() {
            return targetEntity;
        }

        public IDatabaseConnectionHolder connectionHolder() {
            return targetEntity.getConnectionHolder();
        }

        public Builder connectionHolder(IDatabaseConnectionHolder connectionHolder) {
            targetEntity.setConnectionHolder(connectionHolder);
            return this;
        }

        public IDatabase dbOwner() {
            return targetEntity.getDbOwner();
        }

        public Builder dbOwner(IDatabase dbOwner) {
            targetEntity.setDbOwner(dbOwner);
            return this;
        }

        public String dataSourceName() {
            return targetEntity.getDataSourceName();
        }

        public Builder dataSourceName(String dataSourceName) {
            targetEntity.setDataSourceName(dataSourceName);
            return this;
        }

        public IShardingable shardingable() {
            return targetEntity.getShardingable();
        }

        public Builder shardingable(IShardingable shardingable) {
            targetEntity.setShardingable(shardingable);
            return this;
        }


        public String id() {
            return targetEntity.getId();
        }

        public Builder id(String id) {
            targetEntity.setId(id);
            return this;
        }

        public String client() {
            return targetEntity.getClient();
        }

        public Builder client(String client) {
            targetEntity.setClient(client);
            return this;
        }

        public String roleId() {
            return targetEntity.getRoleId();
        }

        public Builder roleId(String roleId) {
            targetEntity.setRoleId(roleId);
            return this;
        }

        public String permissonId() {
            return targetEntity.getPermissonId();
        }

        public Builder permissonId(String permissonId) {
            targetEntity.setPermissonId(permissonId);
            return this;
        }

        public Long createTime() {
            return targetEntity.getCreateTime();
        }

        public Builder createTime(Long createTime) {
            targetEntity.setCreateTime(createTime);
            return this;
        }

        public String groupName() {
            return targetEntity.getGroupName();
        }

        public Builder groupName(String groupName) {
            targetEntity.setGroupName(groupName);
            return this;
        }

        public String permissionName() {
            return targetEntity.getPermissionName();
        }

        public Builder permissionName(String permissionName) {
            targetEntity.setPermissionName(permissionName);
            return this;
        }

        public String permissionCode() {
            return targetEntity.getPermissionCode();
        }

        public Builder permissionCode(String permissionCode) {
            targetEntity.setPermissionCode(permissionCode);
            return this;
        }
    }

    public interface FIELDS {
        String ID = "id";
        String CLIENT = "client";
        String ROLE_ID = "role_id";
        String PERMISSON_ID = "permisson_id";
        String CREATE_TIME = "create_time";
        String GROUP_NAME = "group_name";
        String PERMISSION_NAME = "permission_name";
        String PERMISSION_CODE = "permission_code";
    }

    public static final String TABLE_NAME = "security_role_permission";

    public static FieldConditionBuilder conditionBuilder() {
        return new FieldConditionBuilder();
    }

    public static FieldConditionBuilder conditionBuilder(String prefix) {
        return new FieldConditionBuilder(prefix);
    }

    public static FieldConditionBuilder conditionBuilder(Query<?> query) {
        return conditionBuilder(query, null);
    }

    public static FieldConditionBuilder conditionBuilder(Query<?> query, String prefix) {
        return new FieldConditionBuilder(query.owner(), query.dataSourceName(), prefix);
    }

    public static FieldConditionBuilder conditionBuilder(SecurityRolePermission entity) {
        return conditionBuilder(entity, null);
    }

    public static FieldConditionBuilder conditionBuilder(SecurityRolePermission entity, String prefix) {
        return new FieldConditionBuilder(entity.doGetSafeOwner(), entity.getDataSourceName(), prefix);
    }

    public static FieldConditionBuilder conditionBuilder(IDatabase owner, String prefix) {
        return new FieldConditionBuilder(owner, prefix);
    }

    public static FieldConditionBuilder conditionBuilder(IDatabase owner, String dataSourceName, String prefix) {
        return new FieldConditionBuilder(owner, dataSourceName, prefix);
    }

    public static class FieldConditionBuilder extends AbstractFieldConditionBuilder {

        public FieldConditionBuilder() {
            super(null, null, null);
        }

        public FieldConditionBuilder(String prefix) {
            super(null, null, prefix);
        }

        public FieldConditionBuilder(Query<?> query) {
            super(query.owner(), null, null);
        }

        public FieldConditionBuilder(Query<?> query, String prefix) {
            super(query.owner(), query.dataSourceName(), prefix);
        }

        public FieldConditionBuilder(IDatabase owner) {
            super(owner, null, null);
        }

        public FieldConditionBuilder(IDatabase owner, String prefix) {
            super(owner, null, prefix);
        }

        public FieldConditionBuilder(IDatabase owner, String dataSourceName, String prefix) {
            super(owner, dataSourceName, prefix);
        }

        public FieldCondition id() {
            return createFieldCondition(FIELDS.ID);
        }

        public FieldCondition client() {
            return createFieldCondition(FIELDS.CLIENT);
        }

        public FieldCondition roleId() {
            return createFieldCondition(FIELDS.ROLE_ID);
        }

        public FieldCondition permissonId() {
            return createFieldCondition(FIELDS.PERMISSON_ID);
        }

        public FieldCondition createTime() {
            return createFieldCondition(FIELDS.CREATE_TIME);
        }

        public FieldCondition groupName() {
            return createFieldCondition(FIELDS.GROUP_NAME);
        }

        public FieldCondition permissionName() {
            return createFieldCondition(FIELDS.PERMISSION_NAME);
        }

        public FieldCondition permissionCode() {
            return createFieldCondition(FIELDS.PERMISSION_CODE);
        }
    }
}
